<?php
if (!defined('FosfoaSystem')){exit(1);}
import($GLOBALS['spConfig']['controller_path'] . '/general.php');
class news_comments extends general
{
    public function __construct()
    {
        parent::__construct();
        $this->tpl_title = T("Dashboard");
    }
    function index()
    {
        $this->tt = "评论管理";
        $news_id=$this->spArgs("news_id",0);
        $current_page = $this->spArgs("page", 1);
        $page_size = $this->spArgs("size", 10);

        $obj = spClass("news_commentsModel");
        if($news_id==0){
         $conditions = array('1' => 1);   
        }else{
        $conditions = array('news_id' => $news_id);
        }
        $arr = $obj->spPager($current_page, $page_size)->findAll($conditions, 'news_comments_id desc');
        $arrBar = $obj->spPager()->getPager();
        $this->tPageBar = $arrBar;
        $this->arr = $arr;
        $this->news_id=$news_id;
        $this->display("admin/news_comments_index.html");
    }

    function save()
    {
        $strAction = $this->spArgs("action");
        $data = array(
            "master_categories_id" => $this->spArgs("parent_id"),
            "detail" => array(
                        "news_comments_name" => $this->spArgs("title"),
                        "news_comments_description" => $this->spArgs("content"),
                        "news_comments_seokeywords" => $this->spArgs("news_comments_seokeywords"),
                        "news_comments_seodescription" => $this->spArgs("news_comments_seodescription"),
                        "news_comments_url" => $this->spArgs("news_comments_url",0)
                        ),
            "news_comments_allimg" => $this->spArgs("allimg"),
            "news_comments_image" => $this->spArgs("uploadList")
            );
             
        $Obj = spClass('news_commentsModel');    
        if ($strAction == 'add'){
          $data['news_comments_date_added']=time();
          $Obj->spLinker()->create($data);
          $msg = "信息".$data[detail][news_comments_name]."添加成功";            
        }else
        {
            $data['news_comments_last_modified']=time();
            $news_comments_id =$this->spArgs("id"); 
            $condition = array('news_comments_id' => $news_comments_id);
            $Obj->spLinker()->update($condition, $data);
            $msg = "信息".$data[detail][news_comments_name]."修改成功";     
        }               
        
        Savelog($msg);
        $result = array('status' => 'y',
            'info' => $msg,
            );
        echo json_encode($result);
    }
    function sh()
    {
        $Obj = spClass("news_commentsModel");
        $id2 = $this->spArgs("news_comments_id", 0);
        $news_id = $this->spArgs("news_id", 0);
        $type = $this->spArgs("type", 0);        
        $cid = $this->spArgs("cid", 0);
        $data=array('type'=>$type);        
        if ($id2 == 0)
        {
            $ids = $this->spArgs("selids");
            $idsarray = explode(',', $ids);

            foreach ($idsarray as $id)
            {
                $conditions = array('news_comments_id' => $id);
                $Obj->update($conditions,$data); 
            }
        } else
        {
            $conditions = array('news_comments_id' => $id2);
            $Obj->update($conditions,$data); 
        }
        $msg="评论审核".$id2;
        Savelog($msg);
        $this->success(T('Successfully edited!'), spUrl("news_comments", "index",array("news_id"=>"$news_id")));
    }         
    function del()
    {
        $Obj = spClass("news_commentsModel");
        $news_id = $this->spArgs("news_id", 0);
        $id2 = $this->spArgs("news_comments_id", 0);
        $cid = $this->spArgs("cid", 0);
        if ($id2 == 0)
        {
            $ids = $this->spArgs("selids");
            $idsarray = explode(',', $ids);

            foreach ($idsarray as $id)
            {
                $conditions = array('news_comments_id' => $id);
                $Obj->delete($conditions); // 删除记录
            }
        } else
        {

            $conditions = array('news_comments_id' => $id2);
            $Obj->delete($conditions); // 删除记录
        }
        $msg="评论删除".$id2;
        Savelog($msg);
        $this->success(T('Successfully  deleted!'), spUrl("news_comments", "index",array("news_id"=>"$news_id")));
    }  
}